#标准库，用于创建图形用户界面（GUI），支持窗口、按钮、文本框等控件的创建和管理。
import tkinter as tk
from tkinter import PhotoImage
from tkinter import messagebox
#第三方库，用于图像处理，支持图像打开、编辑、保存、格式转换等操作。Pillow 是 PIL 的现代分支，功能更强大且兼容性更好。
from PIL import Image, ImageTk, ImageDraw, ImageFont
from .Shared import *

#那我问你，为什么我要到处get_player()
player = shareddata.get_player()

#角色界面
class PageRole(tk.Frame):

    def __init__(self, parent):
        super().__init__(parent)
        self.configure(bg = "white", width = 1200, height = 720)
        # 禁止自动调整大小
        self.pack_propagate(False) 
        self.bind("<Expose>", lambda event: self.on_raise(event, parent))
        global player
        #那我问你，为什么我要到处get_player()
        player = shareddata.get_player()

        #加载界面变量
        #界面按钮
        self.pagebuttonlist = []
        self.pagebuttontextlist = ["PageHome", "PageRole", "PageForge", "PageFight", "PageSet"]
        self.pagebuttonid = []
        self.nowpage = 1
        #角色按钮 
        self.characterbuttonlist = []
        self.characterbuttonid = []
        self.characterbuttontextlist = ["KianaZY", "KianaXY", "ElysiaSY", "Mei", "Firefly", "Sirin"]
        self.car = ["Bhp", "Zhp", "Batk", "Zatk", "Bdef", "Zdef", "Bele", "Zele"]
        self.care = ["clothes", "core", "weapon", "enchant", "shoes", "medal"]
        self.nowcharacter = 0
        #装备按钮
        self.equipmentbuttonlist = []
        self.equipmentbuttonid = []
        self.equipmentlist = ["weapon", "enchant", "clothes", "core", "shoes", "medal"]
        self.leftequip = 0
        self.rightequip = 0
        #角色装备
        self.cebuttonlist = []
        self.cebuttonid = []
        #加载图像资源
        self.picture ={
            "PageRole": shareddata.get_picture("PageRole"),
            "Resources": shareddata.get_picture("Resources"),
            "CharacterList": shareddata.get_picture("CharacterList"),
            "EquipmentList": shareddata.get_picture("EquipmentList")
        }
        #加载动画缓冲画布
        self.buffer_image = Image.new("RGBA", (1200, 720), (255, 255, 255, 0))
        self.canvas = tk.Canvas(self, width = 1200, height = 720, highlightthickness = 0, bd = 0)
        self.canvas.place(x = 0, y = 0)

        #界面按钮
        for i in range(5):
            self.pagebuttonlist.append(tk.Canvas(self, bg = "#FFFFFF" if (i != self.nowpage) else "#87CEFA", width = 80, height = 80, highlightthickness = 0, bd = 0))
            self.pagebuttonlist[i].place(x = 600 + 120 * i, y = 10)
            self.pagebuttonid.append(self.pagebuttonlist[i].create_image(0, 0, anchor = tk.NW, image = self.picture["Resources"]["ButtonList"][i][1]))
            self.pagebuttonlist[i].bind("<Enter>", lambda event, i = i: self.mouse_enter(event, self.nowpage, i, self.pagebuttonlist[i]))
            self.pagebuttonlist[i].bind("<Leave>", lambda event, i = i: self.mouse_leave(event, self.nowpage, i, self.pagebuttonlist[i]))
            self.pagebuttonlist[i].bind("<Button-1>", lambda event, i = i: parent.show_frame(self.pagebuttontextlist[i]))
        #角色按钮
        for i in range(6):
            self.characterbuttonlist.append(tk.Canvas(self, bg = "#FFFFFF" if (i != self.nowcharacter) else "#87CEFA", width = 80, height = 80, highlightthickness = 0, bd = 0))
            self.characterbuttonlist[i].place(x = 60, y = 140 + 90 * i)
            self.characterbuttonid.append(self.characterbuttonlist[i].create_image(0, 0, anchor = tk.NW, image = self.picture["CharacterList"]["Icon"][i][1]))
            self.characterbuttonlist[i].bind("<Enter>", lambda event, i = i: self.mouse_enter(event, self.nowcharacter, i, self.characterbuttonlist[i]))
            self.characterbuttonlist[i].bind("<Leave>", lambda event, i = i: self.mouse_leave(event, self.nowcharacter, i, self.characterbuttonlist[i]))
            self.characterbuttonlist[i].bind("<Button-1>", lambda event, i = i: self.show_character(i))
        #装备按钮
        for i in range(min(15, len(player["bag"]))):
            self.equipmentbuttonlist.append(tk.Canvas(self, bg = "#FFFFFF" if (i != self.rightequip) else "#87CEFA", width = 70, height = 70, highlightthickness = 0, bd = 0))
            self.equipmentbuttonlist[i].place(x = 632 + 112 * (i % 5), y = 366 + 112 * (i//5))
            self.equipmentbuttonid.append([self.equipmentbuttonlist[i].create_image(0, 0, anchor = tk.NW, image = self.picture["EquipmentList"]["Frame"][int(player["bag"][i]["No."].split(".")[0])][1]), self.equipmentbuttonlist[i].create_image(10, 10, anchor = tk.NW, image = self.picture["EquipmentList"][player["bag"][i]["No."].split(".")[0]][int(player["bag"][i]["No."].split(".")[1])][1])])
            self.equipmentbuttonlist[i].bind("<Enter>", lambda event, i = i: self.mouse_enter(event, self.rightequip, i, self.equipmentbuttonlist[i]))
            self.equipmentbuttonlist[i].bind("<Leave>", lambda event, i = i: self.mouse_leave(event, self.rightequip, i, self.equipmentbuttonlist[i]))
            self.equipmentbuttonlist[i].bind("<Button-1>", lambda event, i = i: self.show_equipment(i))
        #角色装备按钮
        for i in range(6):
            self.cebuttonlist.append(tk.Canvas(self, bg = "#FFFFFF" if (i != self.rightequip) else "#87CEFA", width = 70, height = 70, highlightthickness = 0, bd = 0))
            self.cebuttonlist[i].place(x = 200 + 310 * (i % 2), y = 130 + 240 * (i // 2))
            self.cebuttonid.append([self.cebuttonlist[i].create_image(0, 0, anchor = tk.NW, image = self.picture["EquipmentList"]["Frame"][int(player["characterlist"][str(self.nowcharacter)]["equip"][self.equipmentlist[i]]["No."].split(".")[0])][1]), self.cebuttonlist[i].create_image(10, 10, anchor = tk.NW, image = self.picture["EquipmentList"][player["characterlist"][str(self.nowcharacter)]["equip"][self.equipmentlist[i]]["No."].split(".")[0]][int(player["characterlist"][str(self.nowcharacter)]["equip"][self.equipmentlist[i]]["No."].split(".")[1])][1])])
            self.cebuttonlist[i].bind("<Enter>", lambda event, i = i: self.mouse_enter(event, self.leftequip, i, self.cebuttonlist[i]))
            self.cebuttonlist[i].bind("<Leave>", lambda event, i = i: self.mouse_leave(event, self.leftequip, i, self.cebuttonlist[i]))
            self.cebuttonlist[i].bind("<Button-1>", lambda event, i = i: self.show_ce(i))

        #角色升级按钮
        self.clubutton = tk.Canvas(self, bg = "#FFFFFF", width = 70, height = 30, highlightthickness = 0, bd = 0)
        self.clubutton.place(x = 645, y = 290)
        self.clubutton.create_image(0, 0, anchor = tk.NW, image = self.picture["Resources"]["EqRmButton"][1])
        self.clubutton.create_text(35, 15, anchor = tk.CENTER, text =  "level up")
        self.clubutton.bind("<Enter>", lambda event: self.mouse_enter(event, 0, 999, self.clubutton))
        self.clubutton.bind("<Leave>", lambda event: self.mouse_leave(event, 0, 999, self.clubutton))
        self.clubutton.bind("<Button-1>", lambda event: self.clu())
        #角色升级十次按钮
        self.clutbutton = tk.Canvas(self, bg = "#FFFFFF", width = 70, height = 30, highlightthickness = 0, bd = 0)
        self.clutbutton.place(x = 645, y = 325)
        self.clutbutton.create_image(0, 0, anchor = tk.NW, image = self.picture["Resources"]["EqRmButton"][1])
        self.clutbutton.create_text(35, 15, anchor = tk.CENTER, text =  "level up*10")
        self.clutbutton.bind("<Enter>", lambda event: self.mouse_enter(event, 0, 999, self.clutbutton))
        self.clutbutton.bind("<Leave>", lambda event: self.mouse_leave(event, 0, 999, self.clutbutton))
        self.clutbutton.bind("<Button-1>", lambda event: self.clut())
        #装备上按钮
        self.eqbutton = tk.Canvas(self, bg = "#FFFFFF", width = 70, height = 30, highlightthickness = 0, bd = 0)
        self.eqbutton.place(x = 1055, y = 295)
        self.eqbutton.create_image(0, 0, anchor = tk.NW, image = self.picture["Resources"]["EqRmButton"][1])
        self.eqbutton.create_text(35, 15, anchor = tk.CENTER, text =  "equip")
        self.eqbutton.bind("<Enter>", lambda event: self.mouse_enter(event, 0, 999, self.eqbutton))
        self.eqbutton.bind("<Leave>", lambda event: self.mouse_leave(event, 0, 999, self.eqbutton))
        self.eqbutton.bind("<Button-1>", lambda event: self.eq())
        #装备拆按钮
        self.edbutton = tk.Canvas(self, bg = "#FFFFFF", width = 70, height = 30, highlightthickness = 0, bd = 0)
        self.edbutton.place(x = 1055, y = 327)
        self.edbutton.create_image(0, 0, anchor = tk.NW, image = self.picture["Resources"]["EqRmButton"][1])
        self.edbutton.create_text(35, 15, anchor = tk.CENTER, text =  "destroy")
        self.edbutton.bind("<Enter>", lambda event: self.mouse_enter(event, 0, 999, self.edbutton))
        self.edbutton.bind("<Leave>", lambda event: self.mouse_leave(event, 0, 999, self.edbutton))
        self.edbutton.bind("<Button-1>", lambda event: self.ed(parent))

        #动画缓冲
        self.update_buffer(parent)

    #界面抬升触发事件（当然不只是界面抬升触发，装备销毁也会触发的喵
    def on_raise(self, event, parent):
        global player
        #那我问你，为什么我要到处get_player()
        player = shareddata.get_player()
        if(len(self.equipmentbuttonlist)<min(15, len(player["bag"]))):
            for i in range (len(self.equipmentbuttonlist), min(15, len(player["bag"]))):
                self.equipmentbuttonlist.append(tk.Canvas(self, bg = "#FFFFFF" if (i != self.rightequip) else "#87CEFA", width = 70, height = 70, highlightthickness = 0, bd = 0))
                self.equipmentbuttonlist[i].place(x = 632 + 112 * (i % 5), y = 366 + 112 * (i//5))
                self.equipmentbuttonid.append([self.equipmentbuttonlist[i].create_image(0, 0, anchor = tk.NW, image = self.picture["EquipmentList"]["Frame"][int(player["bag"][i]["No."].split(".")[0])][1]), self.equipmentbuttonlist[i].create_image(10, 10, anchor = tk.NW, image = self.picture["EquipmentList"][player["bag"][i]["No."].split(".")[0]][int(player["bag"][i]["No."].split(".")[1])][1])])

        for i in range(min(15, len(player["bag"]))):
            self.equipmentbuttonlist[i].place(x = 632 + 112 * (i % 5), y = 366 + 112 * (i//5))
            self.equipmentbuttonlist[i].itemconfig(self.equipmentbuttonid[i][0], image = self.picture["EquipmentList"]["Frame"][int(player["bag"][i]["No."].split(".")[0])][1])
            self.equipmentbuttonlist[i].itemconfig(self.equipmentbuttonid[i][1], image = self.picture["EquipmentList"][player["bag"][i]["No."].split(".")[0]][int(player["bag"][i]["No."].split(".")[1])][1])   
            self.equipmentbuttonlist[i].bind("<Enter>", lambda event, i = i: self.mouse_enter(event, self.rightequip, i, self.equipmentbuttonlist[i]))
            self.equipmentbuttonlist[i].bind("<Leave>", lambda event, i = i: self.mouse_leave(event, self.rightequip, i, self.equipmentbuttonlist[i]))
            self.equipmentbuttonlist[i].bind("<Button-1>", lambda event, i = i: self.show_equipment(i))

        self.update_buffer(parent) 

    #动画缓冲之画面上传
    def update_buffer(self, parent):
        self.buffer_image.paste((255, 255, 255, 0), [0, 0, 1200, 720])
        self.draw_to_buffer(self.buffer_image, parent)
        self.photo_buffer = ImageTk.PhotoImage(self.buffer_image)
        self.canvas.create_image(0, 0, image = self.photo_buffer, anchor = tk.NW)

    #动画缓冲之绘制缓冲画面
    def draw_to_buffer(self, buffer_image, parent):
        global player
        player = shareddata.get_player()
        draw = ImageDraw.Draw(buffer_image)
        headfont = shareddata.get_font(30)
        smallfont = ImageFont.truetype(shareddata.get_font_path(), 15)
        draw.rectangle([0, 0, 1200, 720], fill=(255, 255, 255, 0)) 
        #背景
        buffer_image.paste(self.picture["PageRole"]["BackGround"][0], (0, 0), self.picture["PageRole"]["BackGround"][0])
        #左上头像框   
        buffer_image.paste(self.picture["Resources"]["HeadFrame"][0], (0, 0), self.picture["Resources"]["HeadFrame"][0]) 
        buffer_image.paste(self.picture["Resources"]["KianaHead"][0], (20, 10), self.picture["Resources"]["KianaHead"][0]) 
        buffer_image.paste(self.picture["Resources"]["Crystal"][0], (120, 50), self.picture["Resources"]["Crystal"][0]) 
        buffer_image.paste(self.picture["Resources"]["Coin"][0], (270, 50), self.picture["Resources"]["Coin"][0]) 
        draw.text((120, 15), player["neckname"], font = headfont) 
        draw.text((270, 15), "LV." + str(player["level"]), font = headfont) 
        draw.text((150, 50), ":" + str(player["crystal"]), font = headfont) 
        draw.text((300, 50), ":" + str(player["coin"]), font = headfont)  
        #左侧角色Icon
        #draw.rectangle([50, 130, 150, 680], fill = None, outline = "Black", width = 2)
        buffer_image.paste(self.picture["CharacterList"]["IconFrame"][0], (40, 121), self.picture["CharacterList"]["IconFrame"][0])
        #左侧角色Show
        draw.rectangle([200, 130, 580, 680], fill = None, outline = "Black", width = 2)
        buffer_image.paste(self.picture["CharacterList"]["Icon"][self.nowcharacter][0], (350, 300), self.picture["CharacterList"]["Icon"][self.nowcharacter][0])
        for i in range(3):
            for j in range(2):
                draw.rectangle([200 + 310 * j, 130 + 240 * i, 270 + 310 * j, 200 + 240 * i], fill = None, outline = "Black", width = 2)
                draw.text((200 + 310 * j + 35 - int(len(self.equipmentlist[2 * i + j]) * 4.7), 155 + 240 * i), self.equipmentlist[2 * i + j], fill = "grey", font = smallfont)
        #右上角色att&武器att
        draw.rectangle([630, 130, 1150, 360], fill = None, outline = "Black", width = 2)
        draw.rectangle([910, 130, 910, 360], fill = None, outline = "Black", width = 2)
        draw.rectangle([1030, 130, 1030, 360], fill = None, outline = "Black", width = 2)
        buffer_image.paste(self.picture["CharacterList"]["Icon"][self.nowcharacter][0], (640, 160), self.picture["CharacterList"]["Icon"][self.nowcharacter][0])
        draw.text((670-int(len(str(player["characterlist"][str(self.nowcharacter)]["name"]))*3.5),250), str(player["characterlist"][str(self.nowcharacter)]["name"]), fill = "black", font = smallfont) 
        draw.text((675-int(len("Lv." + str(player["characterlist"][str(self.nowcharacter)]["level"])) * 3.5), 270), "Lv." + str(player["characterlist"][str(self.nowcharacter)]["level"]), fill = "black", font = smallfont)
        for i in range(6):
            draw.text((730, 145 + i * 25), self.car[i] + ":", fill = "black", font = smallfont) 
            draw.text((775, 145 + i * 25), str(player["characterlist"][str(self.nowcharacter)][self.car[i]] + player["characterlist"][str(self.nowcharacter)]["equip"][self.care[i]][self.car[i]]), fill = "green", font = smallfont) 
            draw.text((820, 145 + i * 25), "=" + str(player["characterlist"][str(self.nowcharacter)][self.car[i]]) + "+" + str(player["characterlist"][str(self.nowcharacter)]["equip"][self.care[i]][self.car[i]]), fill = "black", font = smallfont) 
        draw.text((730, 295), "Bele:" + ":", fill = "black", font = smallfont) 
        draw.text((775, 295), str(player["characterlist"][str(self.nowcharacter)]["Bele"] + (player["characterlist"][str(self.nowcharacter)]["equip"]["clothes"]["Bele"] + player["characterlist"][str(self.nowcharacter)]["equip"]["weapon"]["Bele"] + player["characterlist"][str(self.nowcharacter)]["equip"]["shoes"]["Bele"])), fill = "green", font = smallfont) 
        draw.text((820, 295), "=" + str(player["characterlist"][str(self.nowcharacter)]["Bele"]) + "+" + str(player["characterlist"][str(self.nowcharacter)]["equip"]["clothes"]["Bele"] + player["characterlist"][str(self.nowcharacter)]["equip"]["weapon"]["Bele"] + player["characterlist"][str(self.nowcharacter)]["equip"]["shoes"]["Bele"]), fill = "black", font = smallfont) 
        draw.text((730, 320), "Zele:" + ":", fill = "black", font = smallfont) 
        draw.text((775, 320), str(player["characterlist"][str(self.nowcharacter)]["Zele"] + (player["characterlist"][str(self.nowcharacter)]["equip"]["core"]["Zele"] + player["characterlist"][str(self.nowcharacter)]["equip"]["enchant"]["Zele"] + player["characterlist"][str(self.nowcharacter)]["equip"]["medal"]["Zele"])), fill = "green", font = smallfont) 
        draw.text((820, 320), "=" + str(player["characterlist"][str(self.nowcharacter)]["Zele"]) + "+" + str(player["characterlist"][str(self.nowcharacter)]["equip"]["core"]["Zele"] + player["characterlist"][str(self.nowcharacter)]["equip"]["enchant"]["Zele"] + player["characterlist"][str(self.nowcharacter)]["equip"]["medal"]["Zele"]), fill = "black", font = smallfont) 
        #左武器
        buffer_image.paste(self.picture["EquipmentList"]["Frame"][int(player["characterlist"][str(self.nowcharacter)]["equip"][self.equipmentlist[self.leftequip]]["No."].split(".")[0])][0], (935, 140), self.picture["EquipmentList"]["Frame"][int(player["characterlist"][str(self.nowcharacter)]["equip"][self.equipmentlist[self.leftequip]]["No."].split(".")[0])][0])
        buffer_image.paste(self.picture["EquipmentList"][player["characterlist"][str(self.nowcharacter)]["equip"][self.equipmentlist[self.leftequip]]["No."].split(".")[0]][int(player["characterlist"][str(self.nowcharacter)]["equip"][self.equipmentlist[self.leftequip]]["No."].split(".")[1])][0], (945, 150), self.picture["EquipmentList"][player["characterlist"][str(self.nowcharacter)]["equip"][self.equipmentlist[self.leftequip]]["No."].split(".")[0]][int(player["characterlist"][str(self.nowcharacter)]["equip"][self.equipmentlist[self.leftequip]]["No."].split(".")[1])][0])
        if self.leftequip >= 0:
            s = 0
            draw.text((970 - int(len("No.: " + str(player["characterlist"][str(self.nowcharacter)]["equip"][self.equipmentlist[self.leftequip]]["No."].split(".")[3])) * 4), 210 + s), "No.: " + str(player["characterlist"][str(self.nowcharacter)]["equip"][self.equipmentlist[self.leftequip]]["No."].split(".")[3]), fill = "black", font = smallfont) 
            for key, value in player["characterlist"][str(self.nowcharacter)]["equip"][self.equipmentlist[self.leftequip]].items():
                if(key == "No."):
                    continue
                draw.text((970 - int(len(str(key) + ": " + str(player["characterlist"][str(self.nowcharacter)]["equip"][self.equipmentlist[self.leftequip]][key])) * 4), 227 + s), key + ": " + str(player["characterlist"][str(self.nowcharacter)]["equip"][self.equipmentlist[self.leftequip]][key]), fill = "black", font = smallfont) 
                s += 17
        #右武器
        buffer_image.paste(self.picture["EquipmentList"]["Frame"][int(player["bag"][self.rightequip]["No."].split(".")[0])][0], (1055, 140), self.picture["EquipmentList"]["Frame"][int(player["bag"][self.rightequip]["No."].split(".")[0])][0])
        buffer_image.paste(self.picture["EquipmentList"][player["bag"][self.rightequip]["No."].split(".")[0]][int(player["bag"][self.rightequip]["No."].split(".")[1])][0], (1065, 150), self.picture["EquipmentList"][player["bag"][self.rightequip]["No."].split(".")[0]][int(player["bag"][self.rightequip]["No."].split(".")[1])][0])
        if self.rightequip >= 0:
            s = 0
            draw.text((1090 - int(len("No.: " + str(player["bag"][self.rightequip]["No."].split(".")[3])) * 4), 210 + s), "No.: " + str(player["bag"][self.rightequip]["No."].split(".")[3]), fill = "black", font = smallfont) 
            for key, value in player["bag"][self.rightequip].items():
                if(key == "No."):
                    continue
                draw.text((1090 - int(len(str(key) + ": " + str(player["bag"][self.rightequip][key])) * 4), 227 + s), key + ": " + str(player["bag"][self.rightequip][key]), fill = "black", font = smallfont) 
                s += 17
        
    def mouse_enter(self, event, cls, now, canvas):
        canvas.config(bg = "#FFD700" if (now != cls) else "#87CEFA")

    def mouse_leave(self, event, cls, now, canvas):
        canvas.config(bg = "#FFFFFF"  if (now != cls) else "#87CEFA")

    def show_character(self, now):
        self.characterbuttonlist[self.nowcharacter].config(bg = "#FFFFFF")
        self.nowcharacter = now
        self.characterbuttonlist[self.nowcharacter].config(bg = "#87CEFA")
        self.update_buffer(self.master)

    def show_equipment(self, now):
        self.equipmentbuttonlist[self.rightequip].config(bg = "#FFFFFF")
        self.rightequip = now
        self.equipmentbuttonlist[self.rightequip].config(bg = "#87CEFA")
        self.update_buffer(self.master)

    def show_ce(self, now):
        self.cebuttonlist[self.leftequip].config(bg = "#FFFFFF")
        self.leftequip = now
        self.cebuttonlist[self.leftequip].config(bg = "#87CEFA")
        self.update_buffer(self.master)

    def eq(self):
        global player
        #那我问你，为什么我要到处get_player()
        player = shareddata.get_player()
        if(player["bag"][self.rightequip]["type"] == player["characterlist"][str(self.nowcharacter)]["equip"][self.equipmentlist[self.leftequip]]["type"]):
            player["bag"][self.rightequip], player["characterlist"][str(self.nowcharacter)]["equip"][self.equipmentlist[self.leftequip]] = player["characterlist"][str(self.nowcharacter)]["equip"][self.equipmentlist[self.leftequip]], player["bag"][self.rightequip]
            shareddata.set_player(player)
            self.cebuttonlist[self.leftequip].itemconfig(self.cebuttonid[self.leftequip][0], image = self.picture["EquipmentList"]["Frame"][int(player["characterlist"][str(self.nowcharacter)]["equip"][self.equipmentlist[self.leftequip]]["No."].split(".")[0])][1])
            self.cebuttonlist[self.leftequip].itemconfig(self.cebuttonid[self.leftequip][1], image = self.picture["EquipmentList"][player["characterlist"][str(self.nowcharacter)]["equip"][self.equipmentlist[self.leftequip]]["No."].split(".")[0]][int(player["characterlist"][str(self.nowcharacter)]["equip"][self.equipmentlist[self.leftequip]]["No."].split(".")[1])][1])
            self.equipmentbuttonlist[self.rightequip].itemconfig(self.equipmentbuttonid[self.rightequip][0], image = self.picture["EquipmentList"]["Frame"][int(player["bag"][self.rightequip]["No."].split(".")[0])][1])
            self.equipmentbuttonlist[self.rightequip].itemconfig(self.equipmentbuttonid[self.rightequip][1], image = self.picture["EquipmentList"][player["bag"][self.rightequip]["No."].split(".")[0]][int(player["bag"][self.rightequip]["No."].split(".")[1])][1])
            self.update_buffer(self.master)

    def ed(self, parent):
        global player
        #那我问你，为什么我要到处get_player()
        player = shareddata.get_player()
        if(len(self.equipmentbuttonlist) <= 1):
            return
        player["crystal"] += int(player["bag"][self.rightequip]["worth"]/10)
        player["coin"] += int(player["bag"][self.rightequip]["worth"])
        #阴魂不散，删一个小东西这么麻烦
        del player["bag"][self.rightequip]
        canvas = self.equipmentbuttonlist[self.rightequip]
        canvas.delete("all")
        for sequence in canvas.bind():
            canvas.unbind(sequence)
            canvas.unbind(sequence)
            canvas.unbind(sequence)
        canvas.destroy()
        del self.equipmentbuttonlist[self.rightequip]
        del self.equipmentbuttonid[self.rightequip]
        shareddata.set_player(player)
        self.rightequip -= 1
        self.on_raise("<Expose>", parent)
        self.show_equipment(self.rightequip)

    def clu(self):
        global player
        #那我问你，为什么我要到处get_player()
        player = shareddata.get_player()
        if(player["crystal"] >= 100 and player["coin"] >= 100):
            player["characterlist"][str(self.nowcharacter)]["level"] += 1
            player["characterlist"][str(self.nowcharacter)]["Bhp"] += 1
            player["characterlist"][str(self.nowcharacter)]["Batk"] += 1
            player["characterlist"][str(self.nowcharacter)]["Bdef"] += 1
            player["crystal"] -= 100
            player["coin"] -= 100
            shareddata.set_player(player)
            self.update_buffer(self.master)
        else:
            messagebox.showinfo("报错哩！！！", "money不够喵, 快去战斗赚钱喵")

    def clut(self):
        global player
        #那我问你，为什么我要到处get_player()
        player = shareddata.get_player()
        if(player["crystal"] >= 1000 and player["coin"] >= 1000):
            player["characterlist"][str(self.nowcharacter)]["level"] += 10
            player["characterlist"][str(self.nowcharacter)]["Bhp"] += 10
            player["characterlist"][str(self.nowcharacter)]["Batk"] += 10
            player["characterlist"][str(self.nowcharacter)]["Bdef"] += 10
            player["crystal"] -= 1000
            player["coin"] -= 1000
            shareddata.set_player(player)
            self.update_buffer(self.master)
        else:
            messagebox.showinfo("报错哩！！！", "money不够喵, 快去战斗赚钱喵")